package com.hongxun.project.assets.pCablePit.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hongxun.project.assets.pCablePit.mapper.PCablePitMapper;
import com.hongxun.project.assets.pCablePit.domain.PCablePit;
import com.hongxun.project.assets.pCablePit.service.IPCablePitService;
import com.hongxun.common.utils.text.Convert;

/**
 * 电缆井采集 服务层实现
 *
 * @author hongxun
 * @date 2019-03-19
 */
@Service
public class PCablePitServiceImpl implements IPCablePitService {
    @Autowired
    private PCablePitMapper pCablePitMapper;

    /**
     * 查询电缆井采集信息
     *
     * @param id 电缆井采集ID
     * @return 电缆井采集信息
     */
    @Override
    public PCablePit selectPCablePitById(String id, String taskId) {
        return pCablePitMapper.selectPCablePitById(id, taskId);
    }

    @Override
    public PCablePit selectPCablePitByIdForState(String id, String taskId) {
        return pCablePitMapper.selectPCablePitByIdForState(id, taskId);
    }

    /**
     * 查询电缆井采集列表
     *
     * @param pCablePit 电缆井采集信息
     * @return 电缆井采集集合
     */
    @Override
    public List<PCablePit> selectPCablePitList(PCablePit pCablePit) {
        return pCablePitMapper.selectPCablePitList(pCablePit);
    }

    /**
     * 新增电缆井采集
     *
     * @param pCablePit 电缆井采集信息
     * @return 结果
     */
    @Override
    public int insertPCablePit(PCablePit pCablePit) {
        pCablePit.setId(UUID.randomUUID().toString());
        return pCablePitMapper.insertPCablePit(pCablePit);
    }

    /**
     * 修改电缆井采集
     *
     * @param pCablePit 电缆井采集信息
     * @return 结果
     */
    @Override
    public int updatePCablePit(PCablePit pCablePit) {
        return pCablePitMapper.updatePCablePit(pCablePit);
    }

    /**
     * 删除电缆井采集对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePCablePitByIds(String ids) {
        return pCablePitMapper.deletePCablePitByIds(Convert.toStrArray(ids));
    }


    @Override
    public int deletePCablePitByIdsAndTaskIds(String ids, String taskIds) {
        return pCablePitMapper.deletePCablePitByIdsAndTaskIds(Convert.toStrArray(ids), Convert.toStrArray(taskIds));
    }


    @Override
    public void insertOrReplaceOrDelete(List<PCablePit> entities) {
        for (PCablePit d : entities) {
//			if (d.getDatastate().equals("删除")) {
//				pCablePitMapper.deletePCablePitByIdsAndTaskIds(Convert.toStrArray(d.getId()) , Convert.toStrArray(d.getTaskId()));
//			} else {
            PCablePit pCablePit = pCablePitMapper.selectPCablePitById(d.getId(), d.getTaskId());
            if (pCablePit == null) {
                pCablePitMapper.insertPCablePit(d);
            } else {
                pCablePitMapper.updatePCablePit(d);
//				}
            }
        }
    }

}
